<template>
  <van-nav-bar title="消息服务" left-arrow @click-left="router.back()" />

  <div class="notification-list">
    <div
      v-for="item in notifications"
      :key="item.id"
      class="notify-card"
      @click="handleClick(item)"
      :class="{ clickable: item.unread }"
    >
      <div class="notify-icon">
        <van-icon name="envelop-o" color="#ff976a" size="22" />
      </div>
      <div class="notify-content">
        <div class="notify-title">{{ item.title }}</div>
        <div class="notify-desc">{{ item.desc }}</div>
      </div>
      <div class="notify-right">
        <div class="notify-date">{{ item.date }}</div>
        <van-badge v-if="item.unread" dot color="#ee0a24" class="notify-dot" />
        <van-icon name="arrow" color="#c8c9cc" size="18" />
      </div>
    </div>
  </div>

  <van-tabbar v-model="active">
    <van-tabbar-item icon="home-o" to="/HomePage">首页</van-tabbar-item>
    <van-tabbar-item icon="column" to="/Health">科普</van-tabbar-item>
    <van-tabbar-item icon="description" to="/messages">消息</van-tabbar-item>
    <van-tabbar-item icon="contact" to="/Setup">我的</van-tabbar-item>
  </van-tabbar>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter,useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()
const active = ref(2)

const notifications = ref([
  {
    id: 1,
    title: '吃药提醒',
    desc: '早上早餐前请按时吃药',
    date: '2021-05-21',
    unread: true,
    route: '/NotificationDetail'
  },
  {
    id: 2,
    title: '打卡提醒',
    desc: '请记得每日运动打卡哦',
    date: '2021-05-21',
    unread: true,
    route: '/CheckinDetail'
  },
  {
    id: 3,
    title: '打开提醒',
    desc: '成功接受服务，点击查看详情',
    date: '2021-05-21',
    unread: false
  },
  {
    id: 4,
    title: '吃药提醒',
    desc: '签约成功，点击查看详情',
    date: '2021-05-21',
    unread: false
  }
])

function handleClick(item: any) {
  if (item.unread) {
    // 跳转到详情页或消息内容页
    router.push(`${item.route}`)
  }
}
</script>

<style scoped>
.notification-list {
  background: #f7f8fa;
  min-height: calc(100vh - 50px - 50px);
  padding: 16px 0 60px 0;
}
.notify-card {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  margin: 0 16px 16px 16px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px 0 rgba(0,0,0,0.02);
  cursor: default;
  transition: box-shadow 0.2s;
}
.notify-card.clickable {
  cursor: pointer;
}
.notify-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #fff7ed;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 14px;
}
.notify-content {
  flex: 1;
  min-width: 0;
}
.notify-title {
  font-size: 15px;
  font-weight: 600;
  color: #222;
}
.notify-desc {
  font-size: 13px;
  color: #888;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notify-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 70px;
}
.notify-date {
  color: #bcbcbc;
  font-size: 12px;
}
.notify-dot {
  margin-top: 2px;
}
</style>